home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '91 / Hacks '91 / Clarus - the Tail Patch / TailPatch.c < prev   
Encoding:
C/C++ Source or Header  |  1991-06-20  |  2.3 KB  |  143 lines  |  [TEXT/KAHL]

  1. #include <SetUpA4.h>
  2. #include <traps.h>
  3. #include <Sound.h>
  4.  
  5. int                    numPicts;
  6. PicHandle            picts[30];
  7. Handle                moof;
  8. long                oldGND, oldGOSE;
  9. long                lastTicks;
  10. Boolean                inIt;
  11. int                    i;
  12. int                    skipNum;
  13.  
  14.  
  15. pascal DialogPtr    NewGND(short dialogID,void *dStorage,WindowPtr behind);
  16. Boolean                NewGOSE();
  17.  
  18. main()
  19. {
  20.     Handle    h;
  21.     long    *l, j;
  22.       Handle    procH;
  23.       int        cancel;
  24.       Ptr        myPtr;
  25.       Handle    myHandle;
  26.  
  27.     asm {
  28.         move.l    A0,myPtr
  29.     }
  30.     RememberA0();
  31.     SetUpA4();
  32.  
  33.     cancel = FALSE;
  34.       if ((procH = GetResource('PROC', 128)) != 0L)    {
  35.         HLock(procH);
  36.         CallPascal(128, 0, *procH);
  37.         j = TickCount() + 60;
  38.         while (!cancel && TickCount() < j) {
  39.             if (Button()) {
  40.                 cancel = TRUE;
  41.                 CallPascal(129, -1, *procH);
  42.             }
  43.         }
  44.         if (!cancel)
  45.             CallPascal(128, -1, *procH);
  46.         HUnlock(procH);
  47.     } else
  48.         cancel = TRUE;
  49.  
  50.     if (cancel)
  51.         return;
  52.  
  53.     myHandle = RecoverHandle(myPtr);
  54.     DetachResource(myHandle);
  55.  
  56.     moof = GetResource('snd ', 128);
  57.     DetachResource(moof);
  58.  
  59.     numPicts = Count1Resources('PICT');
  60.     for (i = 0; i < numPicts; i++) {
  61.         picts[i] = GetPicture(128 + i);
  62.         DetachResource(picts[i]);
  63.     }
  64.     inIt = FALSE;
  65.     i = 0;
  66.     skipNum = 6;
  67.  
  68.     oldGND = NGetTrapAddress(_GetNewDialog, ToolTrap);
  69.     NSetTrapAddress((long)NewGND, _GetNewDialog, ToolTrap);
  70.     oldGOSE = NGetTrapAddress(_GetOSEvent, OSTrap);
  71.     NSetTrapAddress((long)NewGOSE, _GetOSEvent, OSTrap);
  72.  
  73.     RestoreA4();
  74. }
  75.  
  76.  
  77. pascal DialogPtr
  78. NewGND(short dialogID,void *dStorage,WindowPtr behind)
  79. {
  80.     Rect    r;
  81.     long    result;
  82.     GrafPtr    oldPort;
  83.  
  84.     SetUpA4();
  85.  
  86.     result = CallPascalL(dialogID, dStorage, behind, oldGND);
  87.  
  88.     if (dialogID == 5066) {
  89.         inIt = TRUE;
  90.         lastTicks = TickCount() + 300;
  91.         i = 0;
  92.         skipNum = 6;
  93.     }
  94.     
  95.     RestoreA4();
  96.     
  97.     return (DialogPtr) result;
  98. }
  99.  
  100. Boolean
  101. NewGOSE()
  102. {
  103.     Rect    r;
  104.     Boolean     result;
  105.  
  106.     SetUpA4();
  107.     asm {
  108.         movea.l    oldGOSE,A1
  109.         jsr        (A1)
  110.         move.b    D0,result
  111.     }
  112.  
  113.     if (inIt) {
  114.         if (skipNum > 0)
  115.             skipNum--;
  116.         else {
  117.             if (result) {
  118.                 if (inIt && TickCount() > lastTicks) {
  119.                     r = FrontWindow()->portRect;
  120.                     r.bottom -= 15;
  121.                     DrawPicture(picts[i], &r);
  122.                     lastTicks = TickCount() + 2;
  123.                     if (i == numPicts - 1) {
  124.                         /* MOOF! */
  125.                         SndPlay((SndChannelPtr) 0, moof, FALSE);
  126.                         lastTicks += 60;
  127.                         i--;
  128.                     } else if (i == numPicts - 2) {
  129.                         i--;
  130.                         if (Random() % 50 == 0)
  131.                             i += 2;
  132.                     } else
  133.                         i++;
  134.                 }
  135.             } else {
  136.                 inIt = FALSE;
  137.             }
  138.         }
  139.     }
  140.  
  141.     RestoreA4();
  142.     return result;
  143. }